package br.com.musclebook.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import br.com.musclebook.enums.ExerciseCategory;

@Entity
@Table(name = "EXERCISE")
@Inheritance(strategy = InheritanceType.JOINED)
@NamedQueries({ @NamedQuery(name = "Exercise.findById", query = "select exerc from Exercise exerc left join fetch exerc.exerciseSecondaryCategories where exerc.id = :id") })
public abstract class Exercise implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String name;
    private String description;

    @Enumerated(EnumType.ORDINAL)
    @Column(name = "PRIMARY_CATEGORY")
    private ExerciseCategory primaryCategory;

    @OneToMany(mappedBy = "exercise", cascade = { CascadeType.ALL }, orphanRemoval = true)
    private List<ExerciseSecondaryCategory> exerciseSecondaryCategories;

    public Exercise() {
	
	this.exerciseSecondaryCategories = new ArrayList<ExerciseSecondaryCategory>();
    }

    public Long getId() {
	return id;
    }

    public void setId(Long id) {
	this.id = id;
    }

    public String getName() {
	return name;
    }

    public void setName(String name) {
	this.name = name;
    }

    public String getDescription() {
	return description;
    }

    public void setDescription(String description) {
	this.description = description;
    }

    public ExerciseCategory getPrimaryCategory() {
	return primaryCategory;
    }

    public void setPrimaryCategory(ExerciseCategory primaryCategory) {
	this.primaryCategory = primaryCategory;
    }

    public List<ExerciseSecondaryCategory> getExerciseSecondaryCategories() {
	return exerciseSecondaryCategories;
    }

    public void setExerciseSecondaryCategories(List<ExerciseSecondaryCategory> exerciseSecondaryCategories) {
	this.exerciseSecondaryCategories = exerciseSecondaryCategories;
    }

    public void addExerciseSecondaryCategory(ExerciseSecondaryCategory exerciseSecondaryCategory) {
	this.exerciseSecondaryCategories.add(exerciseSecondaryCategory);
    }

}
